#函数和模块的复习+练习
# import decimal
# import random
import os

#内置函数的使用
# print(len("1"))
# print(bin(2))


#自定义函数
# def send_email():
#     print("发送电子邮件")
#
# send_email()

#内置模块的使用
# num=random.randint(1,100)
# print(type(num),num)


# v1=0.1
# v2=0.2
# print(v1+v2)

#确保浮点数计算机的结果更加精确
# v1=decimal.Decimal("0.1")
# v2=decimal.Decimal("0.2")
# print(v1+v2)

# name="小峰"
# print(name.encode('utf-8'))
# data=b'\xe5\xb0\x8f\xe5\xb3\xb0'
# print(data.decode('utf-8'))

#读取文本文件
# file_object = open('info.txt', 'rt',encoding='utf-8')
# data=file_object.read()
# print(data)
# file_object.close()

# #读取非文本文件的内容
# file_object = open('my.png', 'rb')
# data = file_object.read()
# file_object.close()
# print(data)


#注意路径相关的问题
#file_object = open("D:\python\try1\info.txt","rt")
#file_object = open("D:\\python\\try1\\info.txt","rt")
# file_object = open(r"D:\python\try1\info.txt","rt")

file_path=r"D:\python\try1\info.txt"
exists=os.path.exists(file_path)
if not exists:
    print("文件不存在")
else:
    file_object = open(file_path, "rt",encoding="utf-8")
    data = file_object.read()
    print(data)
    file_object.close()